﻿using System;
using Unity.Mathematics;
using UnityEngine;

namespace GpuHud
{
    //保证对齐,全使用float

    public enum GpuHudCollectionStyleType
    {
        Text,
        Image,
        HelthBar,
        Other
    }
    [Serializable]
    public struct ImageStyleShaderData : StructDataTag
    {
        public float3 Position;
        public float2 Size;
        public float4 UVRect;

        public int GetColorOffset()
        {
            throw new NotImplementedException();
        }

        public int GetParamsCount()
        {
            return 9;
        }

        public int GetPositionOffset()
        {
            throw new NotImplementedException();
        }

        public int GetScaleOffset()
        {
            throw new NotImplementedException();
        }

        public GpuHudCollectionStyleType GetShaderStyleType()
        {
            return GpuHudCollectionStyleType.Image;
        }
    }

    /// <summary>
    /// 考虑效果放到GPU做,CPU除了初始化完全不做
    /// 一个文字 : 21*sizeof(float)
    /// 斜体/渐变在CPU端做
    /// </summary>
    [Serializable]
    public struct TextStyleShaderData : StructDataTag
    {
        [HideInInspector]
        public float4 Position;
        public float2 LocalOffset;
        [HideInInspector]
        public float2 Size;
        [HideInInspector]
        public float4 UVRect;
        public Color FaceColor;
        public float WeightBold;
        public float FaceSoftness;
        public float2 OutLineOffset;
        public Color OutLineColor;
        public float OutLineWeightBold;
        public float OutLineSoftness;
        public float2 Scale;    //x原始scale,y:变更scale
        public float ItalicOffset;
        public float DepthOffset;

        public int GetColorOffset()
        {
            return 12;
        }

        public int GetParamsCount()
        {
            return 30;
        }

        public int GetPositionOffset()
        {
            return 0;
        }

        public int GetScaleOffset()
        {
            return 27;
        }

        public GpuHudCollectionStyleType GetShaderStyleType()
        {
            return GpuHudCollectionStyleType.Text;
        }
    }

    [Serializable]
    public struct HealthBarStyleShaderData : StructDataTag
    {
        public float3 Position;
        public float Percent;
        public float4 UVRectBg;
        public float4 UVRectBar;

        public int GetColorOffset()
        {
            throw new NotImplementedException();
        }

        public int GetParamsCount()
        {
            return 12;
        }

        public int GetPositionOffset()
        {
            throw new NotImplementedException();
        }

        public int GetScaleOffset()
        {
            throw new NotImplementedException();
        }

        public GpuHudCollectionStyleType GetShaderStyleType()
        {
            return GpuHudCollectionStyleType.HelthBar;
        }
    }

    [Serializable]
    public struct CustomStyleShaderData : StructDataTag
    {
        [HideInInspector]
        public float3 Position;
        public float Value;

        public int GetColorOffset()
        {
            throw new NotImplementedException();
        }

        public int GetParamsCount()
        {
            return 4;
        }

        public int GetPositionOffset()
        {
            throw new NotImplementedException();
        }

        public int GetScaleOffset()
        {
            throw new NotImplementedException();
        }

        public GpuHudCollectionStyleType GetShaderStyleType()
        {
            return GpuHudCollectionStyleType.Other;
        }
    }

    /// <summary>
    /// 标记泛型是那种类型
    /// 用于在Collection中进行绘制前数据重构时得到当前泛型的类型信息
    /// 以便根据类型进行重构策略的选择
    /// </summary>
    public interface StructDataTag
    {
        GpuHudCollectionStyleType GetShaderStyleType();
        /// <summary>
        /// 获取Shader的参数个数,用于使用Texture作为参数时的参数传递方案
        /// </summary>
        /// <returns></returns>
        int GetParamsCount();
        /// <summary>
        /// 获取Color参数在ShaderData中的偏移
        /// </summary>
        /// <returns></returns>
        int GetColorOffset();
        /// <summary>
        /// 获取Position参数在ShaderData中的偏移
        /// </summary>
        /// <returns></returns>
        int GetPositionOffset();
        /// <summary>
        /// 获取Scale参数在ShaderData中的偏移
        /// </summary>
        /// <returns></returns>
        int GetScaleOffset();
    }
}